package com.st.bottomnavigation.ui.adapter.test;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.st.bottomnavigation.R;
import com.st.bottomnavigation.bean.test.Student;
import com.st.bottomnavigation.ui.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 停点名称列表-适配类
 */
public class DetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    BaseActivity baseActivity;
    ArrayList<Student> list;//车位数据
    private OnItemClickListener onItemClickListener;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_student_detail, parent, false);
        return new ViewHolder(view);
    }

    // 定义接口用于回调点击事件
    public interface OnItemClickListener {
        void onItemClick(View v,int position);
    }

    public DetailAdapter(ArrayList<Student> list, BaseActivity baseActivity) {
        this.list = list;
        this.baseActivity = baseActivity;
    }

    // 设置点击事件监听器
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public void setData(ArrayList<Student> studentList) {
        list = studentList;
    }


    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        Student student = list.get(position);
        holder.tv1.setText(student.getStuName());
        holder.tv2.setText(student.getSex());


    }

    public final class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv1;
        TextView tv2;
        TextView tv3;

        public ViewHolder(View itemView) {
            super(itemView);
            tv1 = itemView.findViewById(R.id.tv1);
            tv2 = itemView.findViewById(R.id.tv2);
            tv3 = itemView.findViewById(R.id.tv3);

        }
    }

    @Override
    public long getItemId(int index) {
        return index;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }


}
